//
//  InputMoneyTableViewCell.m
//  shanHaiHuiApp
//
//  Created by 小和尚 on 2018/3/10.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "InputMoneyTableViewCell.h"

@interface InputMoneyTableViewCell()<UITextFieldDelegate>

Strong UIImageView * passwordImageView;



@end
@implementation InputMoneyTableViewCell

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    NSString *textStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
    
    [UserModel sharedInstanced].textStr = textStr;
    
    self.strPass = textStr;
    if (_getTextFieldClick) {
        _getTextFieldClick(self);
    }
    
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return [textField resignFirstResponder];
}



#pragma Action--

- (void)tapClick:(UIGestureRecognizer *)sender{
    
    if (_getEyeBtnClick) {
        _getEyeBtnClick(self);
    }
}


#pragma init--

- (id)initWithCellIdentifier:(NSString *)cellID{
    
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        
        _passwordImageView = [UIImageView new];
        _passwordImageView.contentMode = UIViewContentModeScaleAspectFit;
        _passwordImageView.image = [UIImage imageNamed:@"mima"];
        
        _eyeImageView = [UIImageView new];
        _eyeImageView.image = [UIImage imageNamed:@"yangjing_guan"];
        _eyeImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
        [self.eyeImageView addGestureRecognizer:tap];
        
        _passTextField = [[UITextField alloc] init];
        _passTextField.textColor = getColor(@"CCCCCC");
        _passTextField.placeholder = @"请输入支付密码";
        _passTextField.font = DEF_FontSize_14;
        _passTextField.clearButtonMode = UITextFieldViewModeAlways;
        _passTextField.secureTextEntry = YES;
        _passTextField.keyboardType = UIKeyboardTypePhonePad;
        _passTextField.delegate = self;
        
        [self sd_addSubviews:@[self.passwordImageView,self.eyeImageView,self.passTextField]];
        
        [self layOutFrame];
    }
    return self;
}

- (void)layOutFrame{
    ws(self);
    
    [self.passwordImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(UNIT_HEIGHT(15));
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.height.mas_equalTo(UNIT_HEIGHT(23));
        make.width.mas_equalTo(UNIT_WIDTH(18));
    }];
    [self.eyeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.passwordImageView.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(27));
        make.width.mas_equalTo(UNIT_WIDTH(25));
    }];
    
    [self.passTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakself.eyeImageView.mas_left).offset(UNIT_WIDTH(-15));
        make.left.mas_equalTo(weakself.passwordImageView.mas_right).offset(UNIT_WIDTH(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
        make.centerY.mas_equalTo(weakself.passwordImageView.mas_centerY);
    }];
    
    
    
}


@end
